<?php
namespace app\api\controller;
use think\Db;
use think\Controller;
use think\Session;

class Discussion extends Controller
{
    public function release(){
        if(Session::has('uid')){
        if((input('dcontent')!=null)&&(input('sid')!=null)){
        $data=[
        'dcontent'=>input('dcontent'),
        'sid'=>input('sid'),
        'dtime'=>date('Y-m-d H:i:s',time()),
        'uid'=>Session::get('uid'),
        ];
         if( Db::name("discussion")->insert($data)){
           echo json_encode(["status"=>1,"message"=>"success"]);
        }
        else 
        {
          echo json_encode(["status"=>0,"message"=>"fail1"]);
        }
         } 
         else{
            echo json_encode(["status"=>0,"message"=>"fail2"]);
         }
        }
        else 
          echo json_encode(["status"=>0,"message"=>"not login"]);
    }
    
    public function reply(){
        $id=input('did');
        if(Session::has('uid')){
           $data=[
        'did'=>$id,
        'rcontent'=>input('rcontent'),
        'replyid'=>input('replyid'),
        'rtype'=>input('rtype'),
        'rtime'=>date('Y-m-d H:i:s',time()),
        'fromuid'=>Session::get('uid'),
        'touid'=>Session::get('uid'),
        ];
         if( Db::name("reply")->insert($data)){
           echo json_encode(["status"=>1,"message"=>"success"]);
        }
        else{
           echo json_encode(["status"=>0,"message"=>"fail1"]);
         }
    }
        else{
            echo json_encode(["status"=>0,"message"=>"not login"]);
        }
    }
}